package com.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.Set;


//这里不能使用@Data
@Getter
@Setter
@Entity
@Table(name = "DEPARTMENT", uniqueConstraints = { @UniqueConstraint(columnNames = { "DEPT_NO" }) })
public class Department {
    @Id
    @Column(name = "DEPT_ID")
    private Integer deptId;
    @Column(name = "DEPT_NO", length = 20, nullable = false)
    private String deptNo;

    @Column(name = "DEPT_NAME", nullable = false)
    private String deptName;
    @Column(name = "LOCATION")
    private String location;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
    private Set<Employee> employees = new HashSet<Employee>(0);

    public Department() {

    }

    public Department(Integer deptId, String deptName, String location) {
        this.deptId = deptId;
        this.deptNo = "D" + this.deptId;
        this.deptName = deptName;
        this.location = location;
    }
}

